package com.sky.controller;

import com.sky.constant.ShopStatusConstant;
import com.sky.result.Result;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.*;

/**
 * @author iTaotao
 * @version 1.0.0
 * @ClassName ShopStatusController.java
 * @Description 店铺营业状态
 * @createTime 2023年07月31日 15:34:00
 */
@RestController
@RequestMapping("/admin/shop")
public class ShopStatusController {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 获得状态
     *
     * @return {@link Result}<{@link Integer}>
     */
    @GetMapping("/status")
    public Result<Integer> getStatus(){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        Integer shop_status =(Integer) valueOperations.get(ShopStatusConstant.SHOP_STATUS);
        return Result.success(shop_status);
    }


    /**
     * 设置商店状态
     *
     * @param status 状态
     * @return {@link Result}<{@link ?}>
     */
    @PutMapping("/{status}")
    public  Result<?> setShopStatus(@PathVariable Integer status){
        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set(ShopStatusConstant.SHOP_STATUS, status);
        return Result.success();
    }
}
